<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue.js"></script>
    <script src="js/elementUI.js"></script>
    <script src="js/axios.js"></script>
    <link rel="stylesheet" href="css/elementUI.css">
</head>
<body>
<div id="app">
    <el-table
            :data="tableData"
            border
            style="width: 100%">

        <el-table-column
                label="图书">
            <template slot-scope="scope">
                {{scope.row.book==null?'':scope.row.book.name}}
            </template>
        </el-table-column>
        <el-table-column
                label="借阅人">
            <template slot-scope="scope">
                {{scope.row.user==null?'':scope.row.user.username}}
            </template>
        </el-table-column>
        <el-table-column
                prop="borrowTime"
                label="借阅时间">
        </el-table-column>

        <el-table-column
                prop="backTime"
                label="归还时间">
        </el-table-column>

        <el-table-column
                label="操作">
            <template slot-scope="scope">
                <el-button @click="handleEdit(scope.row.id)" type="text" size="small">修改</el-button>
                <el-button type="text" size="small" @click="deleteOne(scope.row.id)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNum"
            :page-sizes="[2, 4, 6, 8]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
    </el-pagination>
</div>
<script>
    new Vue({
        el:"#app",
        data:{
            tableData:[],
            pageNum:1,
            pageSize:2,
            total:0,
            user:{}
        },
        methods:{
            handleSizeChange(val){
                this.pageSize = val;
                this.findPage();
            },
            handleCurrentChange(val){
                this.pageNum=val;
                this.findPage();
            },
            findUser(){
                axios.get("/user/getUser").then(res=>{
                    this.user = res.data;
                    this.findPage();
                })
            },
            findPage(){
                axios.post(`/borrow/findPage?pageNum=${this.pageNum}&pageSize=${this.pageSize}&uid=${this.user.id}`).then(res=>{
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                })
            },
        },
        created(){
            this.findUser();

        }
    })
</script>
</body>
</html>